function relod(){
    layui.use('table', function() {
        var table = layui.table;
        table.reload('test', {
            page: {
                curr: 1 //重新从第一页开始
            }, where: {
                status : 2,
                startTime: $("#test1").val(),
                endTime: $("#test2").val(),
                pid: $("#cgd").val()
            }
        })
    })
}
layui.use('laydate',function () {
    var laydate = layui.laydate;
    laydate.render({
        elem: '#test17'
        ,calendar: true
    });
})

layui.use('table', function(){
    var table = layui.table;
    table.render({
        elem: '#test'
        ,url:'htz/purchaseOrder/all'
        ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
            title: '提示'
            ,layEvent: 'LAYTABLE_TIPS'
            ,icon: 'layui-icon-tips'
        }]
        ,title: '用户数据表'
        ,parseData: function(res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.obj.total, //解析数据长度
                "data": res.obj.list //解析数据列表
            };
        }
        ,cols: [[
            {type: 'checkbox', fixed: 'left',width:40}
            ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
            ,{field:'purchaseOrderCode', title:'采购单Id', width:120,unresize: true, sort: true}
            ,{field:'orderUse', title:'采购单用途', width:190,unresize: true, sort: true}
            ,{field:'sourceId', title:'上游单号', width:120, templet: function(res){
                    if (res.sourceId==null){
                        return "无"
                    }
                    return res.sourceId
                }}
            ,{field:'createDate', title:'生成采购单时间', width:180}
            ,{field:'purchaseOrderCost', title:'预计总金额', width:120}
            ,{field:'status', title:'采购单状态', width:120,templet:function (res) {
                    switch (res.status) {
                        case 1:
                            return "新录入";
                        case 2:
                            return "待审核";
                        case 3:
                            return "审核通过";
                        case 4:
                            return "审核不通过";
                        case 5:
                            return "采购单进行中";
                        case 6:
                            return "已完成";
                    }
                }}
            ,{field:'purchaserName', title:'采购员姓名', width:120}
            ,{field:'auditName', title:'审核人姓名', width:120,templet:function (res) {
                    if (res.auditName==''||res.auditName==null){
                        return "无"
                    }
                    return res.auditName;
                }}
            ,{field:'type', title:'采购单类型', width:120,templet:function (data) {
                    switch (data.type) {
                        case 1:
                            return "新品采购";
                        case 2:
                            return "补货";
                    }
                }}
            ,{field:'payStatus', title:'采购单类型', width:120,templet:function (data) {
                    switch (data.payStatus) {
                        case 1:
                            return "未付款";
                        case 2:
                            return "已付款";
                    }
                }}
            ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:80}
        ]]
        ,page: true
        ,where:{
            status : 2
        }
    });

    //头工具栏事件
    table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'getCheckData':
                var data = checkStatus.data;
                layer.alert(JSON.stringify(data));
                break;
            case 'getCheckLength':
                var data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
                break;
            case 'isAll':
                layer.msg(checkStatus.isAll ? '全选': '未全选');
                break;

            //自定义头工具栏右侧图标 - 提示
            case 'LAYTABLE_TIPS':
                layer.alert('这是工具栏右侧自定义的一个图标按钮');
                break;
        };
    });

    //监听行工具事件
    table.on('tool(test)', function(obj){
        var data = obj.data;
        //console.log(obj)
        if(obj.event === 'look'){
            layui.use('layer',function () {
                var layer = layui.layer
                layer.open({
                    type:2,
                    area: ['600px','400px'],
                    content:'purchase_audit_detail.html',
                    success:function (layero,index) {
                        var iframe = window['layui-layer-iframe'+index]
                        iframe.relod(data.id);
                    }
                })
            })
        }
    });
});